<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>求职者信息管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="layui/css/layui.css" media="all">
	<link rel="stylesheet" href="css/public.css" media="all">
	<style type="text/css">
		.layui-table-cell {
			height: auto;
			/*line-height: 28px;*/
		}
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">发布者</label>
							<div class="layui-input-inline">
								<input type="text" name="u_name" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">招聘单位</label>
							<div class="layui-input-inline">
								<input type="text" name="department" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">标题</label>
							<div class="layui-input-inline">
								<input type="text" name="title" autocomplete="off" class="layui-input">
							</div>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">发布时间</label>
							<div class="layui-input-inline">
								<input type="text" name="time" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
<!--				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加信息 </button>-->
				<button id="deleteList" class="layui-btn layui-btn-sm layui-btn-disabled data-delete-btn" lay-event=""> 批量删除 </button>
			</div>
		</script>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter" ></table>

		<script type="text/html" id="currentTableBar">
			<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detail">详情</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
		</script>

	</div>
</div>
<script src="layui/layui.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/jquery-3.6.3.js"></script>
<script>

	layui.use(['form', 'table'], function () {
		var $ = layui.jquery,
				form = layui.form,
				table = layui.table;


		table.render({
			elem: '#currentTableId',
			url: '/findListZpZixun',
			toolbar: '#toolbarDemo',
			even: true,
			defaultToolbar: ['filter', 'exports', 'print', {
				title: '提示',
				layEvent: 'LAYTABLE_TIPS',
				icon: 'layui-icon-tips'
			}],
			cols: [
					[
						{type: "checkbox", width: 50,},
						{field: 'id', width: 80, title: 'ID', sort: true,align:"center"},
						{field: 'u_name', width: 200, title: '发布者',align:"center"},
						{field: 'department', width: 200, title: '单位',align:"center"},
						{field: 'title', width: 200,title: '标题',align:"center"},
						{field: 'photo', width:200,title: '图片', align:"center",
							templet:function (d) { return '<div><img src="uploadImages/'+d.photo+'", ' +
									'style="width: 200px;height: 100px"></div>'}},
						{field: 'content', width: 250,title: '内容',align:"center"},
						{field: 'time', width: 200,title: '发布时间',align:"center"},
						{title: '操作', minWidth: 200,toolbar: '#currentTableBar', align: "center"}
					]
			],
			limits: [5, 10, 15, 20, 25, 50],
			limit: 5,
			page: true,
			parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
			var result;
			if (this.page.curr) {
				result = res.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
			}
			else {
				result = res.slice(0, this.limit);
			}
			return {
				"code": 0, //解析接口状态
				"msg": '', //解析提示文本
				"count": res.length, //解析数据长度
				"data": result //解析数据列表
			};
		}
		});


		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			//JSON.stringify(data.field)
			var user = {};
			if (data.field.u_name !== ''){
				user.u_name = data.field.u_name;
			}
			if(data.field.title !== ''){
				user.title = data.field.title;
			}
			if(data.field.time !== ''){
				user.time = data.field.time;
			}
			//执行搜索重载
			table.reload('currentTableId', {
				data:user,
				method:'post',
				url:'/zp_zixun_search',
				contentType:'application/json;charset=utf-8',
				page: {
					curr:1
				},
				where:data.field
			}, 'data');

			return false;
		});

		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			// if (obj.event === 'add') {  // 监听添加操作
			// 	var index = layer.open({
			// 		title: '添加求职者信息',
			// 		type: 2,
			// 		shade: 0.2,
			// 		maxmin:true,
			// 		shadeClose: true,
			// 		area: ['100%', '100%'],
			// 		content: '/toqzAdd',
			// 	});
			// 	$(window).on("resize", function () {
			// 		layer.full(index);
			// 	});
			// } else
				if (obj.event === 'delete') {  // 监听删除操作
				var checkStatus = table.checkStatus('currentTableId')
						, data = checkStatus.data;
				layer.confirm('真的删除行么', function (index) {
					$.ajax({
						type: 'POST',
						url: window.location.protocol + '//' + window.location.host + '/deleteZpZixunList',
						dataType: 'html',
						data: JSON.stringify(data),
						contentType: 'application/json',
						success: function (data) {
							// 关闭弹出层
							if (data) {
								//obj.del();
								layer.msg("删除成功！");
								layer.close(index);
								table.reload($("table")[0].id, {});//刷新table
								// window.location.reload();
								// setTimeout(function() {
								// 	window.location.reload();
								// }, 500);
							} else {
								layer.msg("服务器异常，请稍后重试！");
							}

						},
						error: function () {
							//console.log(data);
							//layer.close(registerLoadIndex);
							layer.alert("请求超时！")
						}
					});
				})
			}
		});

		//监听表格复选框选择
		table.on('checkbox(currentTableFilter)', function (obj) {
			//console.log(obj.checked);
			var state = obj.checked;
			if (state){
				var obj1 = document.getElementById("deleteList");
				obj1.className = "layui-btn layui-btn-sm layui-btn-danger data-delete-btn";
				obj1.setAttribute('lay-event','delete')
			}else {
				var obj1 = document.getElementById("deleteList");
				obj1.className = "layui-btn layui-btn-sm layui-btn-disabled";
				obj1.setAttribute('lay-event','')
			}
		});

		//监听详情、删除
		table.on('tool(currentTableFilter)', function (obj) {
			var data1 = obj.data;
			if (obj.event === 'detail') {
				var index = layer.open({
					title:false,
					type: 2,
					shade: 0.2,
					maxmin: false,
					shadeClose: true,
					area: ['700px', '500px'],
					content: '/toZixunDetail?id=' + data1.id,
				});
				$(window).on("resize", function () {
					layer.full(index);
				});
				return false;
			} else
				if (obj.event === 'delete') {
				layer.confirm('真的删除行么', function (index) {
					$.ajax({
						type: 'POST',
						url: window.location.protocol + '//' + window.location.host + '/deleteZpZixun',
						dataType: 'html',
						data: JSON.stringify(data1),
						contentType: 'application/json',
						success: function (data) {
							// 关闭弹出层
							if (data) {
								obj.del();
								layer.msg("删除成功！");
								layer.close(index);
							} else {
								layer.msg("服务器异常，请稍后重试！");
							}

						},
						error: function () {
							//console.log(data);
							//layer.close(registerLoadIndex);
							layer.alert("请求超时！")
						}
					});
				})
			}
		})

	});
</script>

</body>
</html>